<?php

class Form_Admin extends QForm
{
    function __construct($action)
    {
        // 调用父类的构造函数
        parent::__construct('form_admin', $action);

        // 从配置文件载入表单
        $filename = rtrim(dirname(__FILE__), '/\\') . DS . 'admin_form.yaml.php';
        $this->loadFromConfig(Helper_YAML::loadCached($filename));
        $this->addValidations(Admin::meta()); 
        
   	 	$app = Q::registry('app');
        $user = $app->currentUser();
		$this['groupid']->items = Group::find('isdelete=0 and id <> 4')->getAll()->toHashMap('id','groupname');
      	$this['newpassword']->addValidations(array($this, 'checkpassword'), null, '两次输入的密码不同！');
      	$this['password']->addValidations(array($this, 'checkpwd'), null, '密码不能包含空格！');
      	$this['password']->addValidations(array($this, 'checkpwd2'), null, '密码不能为空！');
      	//$this['newpassword']->addValidations(array($this, 'checknpwd'), null, '确认密码不能为空！');
    }
    
    
	function checkpassword() {
		$context=QContext::instance();
		return $context->newpassword == $context->password;
	}
	function checknpwd() {
		$context=QContext::instance();
		return !empty($context->newpassword);
	}

	
	function checkpwd(){
		$password=QContext::instance()->password;
		//return $this->edit==1 || !empty($password);
		return strpos($password, ' ') === false;
	}
	function checkpwd2(){
		$password=QContext::instance()->password;
		return $this->edit==1 || $password != '';
	}
}

